//
//  CabinetCell.m
//  YunGui
//
//  Created by Hanen 3G 01 on 16/3/22.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "CabinetCell.h"
#import "NetModel.h"


@interface CabinetCell ()
{

    CGFloat   space;
    UIView *verline2;
    UILabel *verline1;
    UIImageView *imageView;
    UIView    *_bottomLine;
    
    
}
@property (nonatomic, strong) UILabel  *titleLabel1;
@property (nonatomic, strong) UILabel  *titleLabel2;
@property (nonatomic, strong) UILabel  *timelabel;
@property (nonatomic, strong) UILabel  *addresslabel;
@property (nonatomic, strong) UILabel  *installPlaceLabel;

@property (nonatomic, strong) UIImageView  *timeImage;
@property (nonatomic, strong) UIImageView  *addressImage;
@property (nonatomic, strong) UIImageView  *installPlaceImage;
@property (nonatomic, strong) UIImageView  *qualifiedImage;//合格不合格的图片

@end

@implementation CabinetCell
+ (instancetype)cellWithTabelView:(UITableView *)tableView
{
    static NSString *CabinetCellID = @"CabinetCellID";
    
    CabinetCell *cell = [tableView dequeueReusableCellWithIdentifier:CabinetCellID];
    
    if (!cell) {
        cell = [[CabinetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CabinetCellID];
        [cell addSubviews];
    }
    return cell;
}
- (void)addSubviews
{
    space = [UIView getWidth:10.0f];
    
    CGFloat cellH = [CabinetCell cellHeight];
    
//    verline1 = [[UILabel alloc] initWithFrame:CGRectMake(3 * space, 0, 3, 1.5 * space)];
//    verline1.backgroundColor = GrayVerLineColor;
//    [self.contentView addSubview:verline1];
    
//    CGFloat circleW = 15.0;
//   imageView = [[UIImageView alloc] initWithFrame:CGRectMake(verline1.x + verline1.width / 2.0f - circleW / 2.0f, verline1.maxY + 3 , circleW, circleW)];
//    imageView.image = [UIImage imageNamed:@"Btn_Normal_Shijianquan"];

//    imageView.layer.cornerRadius = imageView.width / 2.0f;
//    imageView.layer.masksToBounds = YES;
//    [self.contentView addSubview:imageView];
    
//    verline2 = [[UIView alloc] initWithFrame:CGRectMake(verline1.x , imageView.maxY + 3, verline1.width , cellH - imageView.maxY)];
//    verline2.backgroundColor = GrayVerLineColor;
//    [self.contentView addSubview:verline2];
//    
    _bottomLine = [ViewTool getLineViewWith:CGRectMake(1.5 * space, cellH - 1, kScreenWidth, 1) withBackgroudColor:GrayLineColor];
    [self.contentView addSubview:_bottomLine];
    
    _titleLabel1 = [ViewTool getLabelWith:CGRectMake(_bottomLine.x, 1.5 *space , 200, 20.0f) WithTitle:@"OJS-YZ-0141238" WithFontSize:15.0f WithTitleColor:BLACKTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_titleLabel1];
    
    _titleLabel2 = [ViewTool getLabelWith:CGRectMake(_titleLabel1.x, _titleLabel1.maxY + space / 2.0f, [UIView getWidth:180], 15.0f) WithTitle:@"滨江二村" WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_titleLabel2];
    
    CGFloat imageWidth = 17.0f;
    _timeImage = [[UIImageView alloc] initWithFrame:CGRectMake(_titleLabel2.x, _titleLabel2.maxY + 1.2 * space, imageWidth, imageWidth)];
    _timeImage.image = [UIImage imageNamed:@"Btn_Normal_Shijian"];
//    _timeImage.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_timeImage];
    
    
    _timelabel = [ViewTool getLabelWith:CGRectMake(_timeImage.maxX + 5, _timeImage.y - 2, [UIView getWidth:180], 20.0f) WithTitle:@"检查时间:2016：03：05" WithFontSize:14.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
//    _timelabel.backgroundColor = BlueColor;
    [self.contentView addSubview:_timelabel];
    
//    _addressImage = [[UIImageView alloc] initWithFrame:CGRectMake(_timeImage.x, _timelabel.maxY + space / 2.0, imageWidth, imageWidth)];
//    _addressImage.image = [UIImage imageNamed:@"Btn_Normal_Dizhi"];
////    _addressImage.backgroundColor = [UIColor orangeColor];
//    [self.contentView addSubview:_addressImage];
    
    
//    _addresslabel = [ViewTool getLabelWith:CGRectMake(_addressImage.maxX + 5, _addressImage.y - 2, [UIView getWidth:200], 20.0f) WithTitle:@"网点地址:扬州仪征扬子西路185号" WithFontSize:14.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
//    _addresslabel.backgroundColor = BlueColor;
//    [self.contentView addSubview:_addresslabel];
    
    _installPlaceImage = [[UIImageView alloc] initWithFrame:CGRectMake(_timeImage.x, _timeImage.maxY + space / 2.0, imageWidth, imageWidth)];
    _installPlaceImage.image = [UIImage imageNamed:@"Btn_Nor_Anzhuangweizhi"];
//    _installPlaceImage.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_installPlaceImage];
    
    _installPlaceLabel = [ViewTool getLabelWith:CGRectMake(_installPlaceImage.maxX + 5, _installPlaceImage.y - 2, [UIView getWidth:180], 20.0f) WithTitle:@"安装位置:小区传达室旁边" WithFontSize:14.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
//    _installPlaceLabel.backgroundColor = BlueColor;
    [self.contentView addSubview:_installPlaceLabel];
    
    _qualifiedImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIView getWidth:47.0f], [UIView getWidth:47.0f])];
    _qualifiedImage.center = CGPointMake( _timelabel.maxX + 6 * space, cellH / 2.0f - space);
    _qualifiedImage.layer.cornerRadius = _qualifiedImage.width / 2.0f;
    _qualifiedImage.layer.masksToBounds = YES;
    _qualifiedImage.backgroundColor = BlueColor;
    [self.contentView addSubview:_qualifiedImage];
    
}
- (void)setModel:(NetModel *)model{
    _model = model;
    _titleLabel1.text = [NSString stringWithFormat:@"%@",model.branch_no];
    _titleLabel2.text = model.branch_name;
    _timelabel.text = [NSString stringWithFormat:@"检查时间:%@",model.checked_at];
    _installPlaceLabel.text = [NSString stringWithFormat:@"安装位置:%@",model.address];
    if ([model.status intValue]== 2) {
        _qualifiedImage.image = [UIImage imageNamed:@"Btn_Normal_Buhege"];
        
    }else if([model.status intValue] == 1){
        _qualifiedImage.image = [UIImage imageNamed:@"Btn_Normal_Hege"];
    }else if([model.status intValue] == 0){
        _qualifiedImage.image = [UIImage imageNamed:@"Btn_Normal_Weijiancha"];
    }
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    verline1.backgroundColor = GrayVerLineColor;
    verline2.backgroundColor = GrayVerLineColor;

     _bottomLine.backgroundColor = GrayLineColor;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    verline1.backgroundColor = GrayVerLineColor;
    verline2.backgroundColor = GrayVerLineColor;

    _bottomLine.backgroundColor = GrayLineColor;

}
+ (CGFloat)cellHeight
{
    return [UIView getHeight:110];
}
@end
